Skip to content

fix(id-web): keep marks spanning inline HTML atoms as one span on save (#1412) - #1505

Merged
dezren39 merged 1 commit into
mainfrom
queue/1481-1412-html-inline-marks
Oct 28, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/1481-1412-html-inline-marks

Conversation

@dezren39

@dezren39 dezren39 commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Fixes #1412.

Problem

In pkgs/id's web markdown codec, a mark spanning an html_inline atom fragmented on save: [a <b>x</b> c](/y) saved as [a ](/y)<b>[x](/y)</b>[ c](/y), and emphasis forms leaked &#32; entities at the seams. The parse direction emits html_inline atoms markless by design, so the save direction saw marked run → bare atom → marked run, and the atom landing as a sibling severed the tail mark wrapper.

Fix

append_inline_child (save side, pkgs/id/src/web/markdown.rs): before inserting a peeled mark chain, adopt_trailing_html_atoms moves any trailing html_inline atoms into the tail mark wrapper when the incoming chain shares that wrapper's mark — recursing along the chain's shared marks (mirroring insert_marked_chain's descent) so nested spans adopt at the deepest shared level. The chain then merges into the same wrapper as usual, emitting one span containing the tags. Atoms not followed by a chain sharing the preceding wrapper's mark keep their legacy sibling placement (unmarked HTML, atoms after a finished span, and the single-run [<b>x</b>](/y) form are unchanged). The helper's atom predicate is the generalization point for the sibling image-atom case (#1407).

Tests

New regression tests in web::markdown:

  • test_marks_spanning_inline_html_roundtrip — link/sup, emphasis, strong, strikethrough spans and consecutive-atom cases round-trip byte-identically with no &#32;.
  • test_marks_spanning_inline_html_pm_to_md — save direction alone from hand-built PM.
  • test_inline_html_outside_marks_stays_outside — controls: unmarked atoms and post-span atoms keep placement; single-run form re-parses to the identical PM structure.

Verified on the laptop worktree: cargo test --offline --features web --lib web::markdown — 88 passed (the two spanning tests failed with the exact issue output before the fix); rustfmt --check clean.

Queue task 1481 (repo-health-code-pilot).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner October 27, 2026 19:12
@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 002a26fa-e1ce-4480-8ffa-88904418e2a3
Commits

Reviewing files that changed from the base of the PR and between 931f177 and 93cf8b8.

Files selected for processing: 1
  • pkgs/id/src/web/markdown.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T19:16:27.107390Z 93cf8b8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93cf8b887c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1757 to +1759
for atom in &children[split..] {
atom.detach();
tail.append(atom);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve HTML boundaries between independent marked spans

When two separate marked spans surround an opening HTML tag, adopting that tag changes their nesting and can change rendered formatting. For example, *a*<span style="font-style: normal">*b*</span> now saves as *a<span style="font-style: normal">b*</span>, leaving the closing HTML tag outside the emphasis wrapper. Previously the inner <em> made b italic; after saving, the span's explicit normal style overrides the enclosing emphasis and b is no longer italic. Matching marks on either side alone does not establish that the intervening HTML belongs inside the mark; preserve boundaries for HTML elements that extend beyond the marked span.

Useful? React with 👍 / 👎.

Comment on lines +1733 to +1734
let children: Vec<&'a AstNode<'a>> = parent.children().collect();
let mut split = children.len();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Inspect only trailing siblings instead of collecting every child

For a long paragraph containing alternating marked and unmarked runs, such as repeated *a* b , every marked run now collects all previously appended siblings even though there are no HTML atoms to adopt. Since append_inline_child calls this helper for every marked chain, a paragraph with n such runs incurs Θ(n²) sibling visits and repeated allocations, whereas the previous tail insertion only inspected the last child. This introduces quadratic work on ordinary Markdown saves through convert_doc_to_bytes. Walk backward from last_child() through only the trailing HTML atoms, returning immediately when the last child is not HTML.

Useful? React with 👍 / 👎.

@dezren39
dezren39 merged commit a120b9a into main Oct 28, 2026
32 checks passed
@dezren39
dezren39 deleted the queue/1481-1412-html-inline-marks branch October 28, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id(web): marks spanning inline HTML are broken on save — links fragment around the tags, emphasis leaks &#32; entities

1 participant